package command

import (
	"ssdevice/common/dto"
	"ssdevice/common/utils"
	"ssdevice/internal/device/models"
	"strings"
	"time"
)

type ReportFromInsertReq struct {
	Name         string                 `json:"name"`
	UserId       string                 `json:"userId"`
	QueryData    map[string]interface{} `json:"queryData" `
	dto.UserInfo `search:"-"`
}

func (d *ReportFromInsertReq) Generate(model *models.SysReportForms) error {

	model.Id = utils.SimpleUUID()
	model.Name = strings.TrimSpace(d.Name)
	model.UserId = d.UserId
	model.QueryData = utils.MapToBytes(utils.If(len(d.QueryData) > 0, d.QueryData, map[string]interface{}{}).(map[string]interface{}))

	now := dto.LocalTime(time.Now())
	model.CreateTime = &now
	return nil
}

type ReportFromUpdateReq struct {
	Id           string                 `json:"id" vd:"len($)>0"`
	Name         string                 `json:"name"`
	UserId       string                 `json:"userId"`
	QueryData    map[string]interface{} `json:"queryData" `
	dto.UserInfo `search:"-"`
}

func (d *ReportFromUpdateReq) Generate(model *models.SysReportForms) error {

	model.Id = d.Id
	model.Name = strings.TrimSpace(d.Name)
	model.Name = strings.TrimSpace(d.Name)
	model.UserId = d.UserId
	model.QueryData = utils.MapToBytes(utils.If(len(d.QueryData) > 0, d.QueryData, map[string]interface{}{}).(map[string]interface{}))

	now := dto.LocalTime(time.Now())
	model.CreateTime = &now

	return nil
}

type ReportFromDeleteReq struct {
	Id           string `json:"id" vd:"len($)>0"`
	dto.UserInfo `search:"-"`
}
